<!--
 * @author guojiteng
 -->
<template>
  <div id="hndetail">
    <div v-show="searchshow" class="hndetail-search">
      <el-collapse-transition>
        <div v-show="searchshow" class="course-search merge">
          <span class="svg-container">
            <svg-icon icon-class="search" />
          </span>
          <el-input v-model.trim="listQuery.userName" placeholder="请输入姓名搜索" class="search-input" />
          <div class="course-search-btn">
            <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
            <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
            <span class="course-search-more" @click="searchshow = !searchshow">
              更多筛选条件
              <i class="el-icon-arrow-down" />
            </span>
          </div>
        </div>
      </el-collapse-transition>
    </div>

    <el-collapse-transition>
      <div v-show="!searchshow" class="course-search separate">
        <div class="course-search-inner">
          <el-row>
            <el-col :span="12">
              <div class="search-inner-item">
                <div class="item-label">姓名</div>
                <el-input v-model.trim="search.userName" style="width: 80%" class="filter-item" placeholder="请输入姓名搜索" />
              </div>
            </el-col>
            <el-col :span="12">
              <div class="search-inner-item">
                <div class="item-label">手机号码</div>
                <el-input v-model.trim="search.phoneNum" style="width: 80%" class="filter-item" placeholder="请输入手机号码搜索" />
              </div>
            </el-col>
            <el-col :span="12">
              <div class="search-inner-item">
                <div class="item-label">证件号码</div>
                <el-input v-model.trim="search.idCard" style="width: 80%" class="filter-item" placeholder="请输入证件号码搜索" />
              </div>
            </el-col>
          </el-row>
        </div>
        <div class="course-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="course-search-more" @click="searchshow = !searchshow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </div>
      </div>
    </el-collapse-transition>

    <div class="btn-container">
      <div class="btn-container-title">
        <span>报名详情</span>
      </div>
      <div class="btn-container-btns">
        <el-button
          v-loading.fullscreen.lock="fullscreenLoading"
          class="filter-item"
          style="margin-left: 10px;"
          @click="exportFun"
        >导出</el-button>

        <el-button
          class="filter-item"
          style="margin-left: 10px;"

          @click="back"
        >返回</el-button>
      </div>
    </div>
    <section class="classify-tab">
      <el-tabs v-model="activeTab" @tab-click="handleTabClick">
        <el-tab-pane v-for="item in option" :key="item.id" :label="item.name" :name="item.id" />
      </el-tabs>
    </section>
    <div class="table">
      <my-table
        :list="list"
        tag="hndetail"
        :filter-column="filtercolumn"
        operationwidth="80"
        :list-loading="listLoading"
        @handleSelectionChange="handleSelectionChange"
      >
        <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleDetail(scope.row)">
              {{ activeTab=='0'?'审核':'查看详情' }}
            </el-button>
          </template>
        </el-table-column>
      </my-table>
    </div>
    <div class="btn-pagion fix">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
  </div>
</template>

<script>
import { queryPage } from '@/views/staffserve/ghhn/api/detail'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import permission from '@/directive/permission/index.js' // 权限判断指令
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
import MyTable from '@/components/Table'
import { exportSign } from '@/utils/fileImportOrExportSign'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
import { maskAPI, noMaskAPI } from '@/views/staffserve/ghhn/api/detail'
import CryptoJS from '@/utils/aesJiaJM'
export default {
  name: 'Detailmanage',
  components: { Pagination, MyTable },
  directives: { permission, elDragDialog },
  data() {
    return {
      activeTab: '0',
      fullscreenLoading: false,
      option: [
        {
          name: '待审核',
          id: '0'
        },
        {
          name: '通过',
          id: '1'
        },
        {
          name: '驳回',
          id: '2'
        }
      ],
      searchshow: true,
      multipleSelection: [],
      listQuery: {
        page: 1,
        limit: 10,
        userName: ''
      },
      search: {
        userName: '',
        phoneNum: '',
        idCard: ''
      },
      list: [],
      total: 0,
      hdid: '', // 活动id
      qdid: ''// 签到id
    }
  },
  created() {
    if (this.$route.query.i) {
      if (this.$route.query.t) {
        this.activeTab = this.$route.query.t
      }
      this.hdid = this.$route.query.i
      this.getList()
    } else {
      this.$router.back()
    }
  },
  methods: {
    handleDetail(row) {
      this.$router.push({ path: this.$filterPath('info'), query: { i: row.id, hi: this.$route.query.i, t: this.activeTab }})
    },
    back() {
      this.$router.replace({ path: this.$filterPath('index') })
    },
    filtercolumn(scope, item) {
      const ths = this
      if (item === 'phoneNum' || item === 'idCard') {
        return CryptoJS.$aesJieM(scope.row[item])
      } else if (item === 'num') {
        return scope.$index + 1 + (ths.listQuery.page - 1) * ths.listQuery.limit
      } else if (item === 'sex') {
        return scope.row[item] === 'MAN' ? '男' : '女'
      }
      return scope.row[item]
    },
    handleTabClick(tab, event) {
      this.listQuery.page = 1
      this.getList()
    },
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    },
    exportFun() {
      // if(this.list.length==0){
      //   this.$message.error('暂无数据')
      //   return
      // }
      var query = {
        page: this.listQuery.page,
        pageSize: this.listQuery.limit,
        type: 4,
        dataId: this.hdid,
        authStatus: this.activeTab
      }
      if (this.searchshow) {
        query['userName'] = this.listQuery.userName
      } else {
        query['userName'] = this.search.userName
        query['phoneNum'] = this.search.phoneNum
        query['idCard'] = this.search.idCard
      }
      const obj = exportSign(query).obj
      exportCheck('STAFF_SERVICE_FELLOWSHIP', this.hdid, maskAPI, noMaskAPI, obj, '报名详情.xls')
      // exportData(obj).then(res => {
      //   const content = res.data
      //   const blob = new Blob([content])
      //   const fileName = '报名详情.xls'
      //   if ('download' in document.createElement('a')) {
      //     // 非IE下载
      //     const elink = document.createElement('a')
      //     elink.download = fileName
      //     elink.style.display = 'none'
      //     elink.href = URL.createObjectURL(blob)
      //     document.body.appendChild(elink)
      //     elink.click()
      //     URL.revokeObjectURL(elink.href) // 释放URL 对象
      //     document.body.removeChild(elink)
      //   } else {
      //     // IE10+下载
      //     navigator.msSaveBlob(blob, fileName)
      //   }
      //   this.fullscreenLoading = false
      //   // eslint-disable-next-line handle-callback-err
      // }).catch(err => {
      //   this.fullscreenLoading = false
      // })
    },
    /**
     * 查询列表
     */
    getList(obj) {
      const _this = this
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        type: 4,
        dataId: this.hdid,
        authStatus: this.activeTab
      }
      if (this.searchshow) {
        query['userName'] = this.listQuery.userName
      } else {
        query['userName'] = this.search.userName
        query['phoneNum'] = this.search.phoneNum
        query['idCard'] = this.search.idCard
      }
      this.listLoading = true
      return new Promise((resolve, reject) => {
        queryPage(query, this.activeTab).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          _this.listLoading = false
        }).catch(error => {
          _this.listLoading = false
          reject(error)
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.userName = ''
      this.listQuery.page = 1
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    getImg() {
      downImg({ id: this.temp.id }).then(res => {
        console.log('图片', res)
        const blob = new Blob([res.data], { type: 'image/jpg' })
        this.imageUrl = window.URL.createObjectURL(blob)
      }).catch(() => {
        this.$message.error('请求失败')
      })
    }

  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" type="text/scss">
$dark_gray: #bfced6;
@import '@/styles/mixin.scss';
#hndetail {
  padding: 10px;
  .avatar-uploader .el-upload {
    margin-bottom: 10px;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .el-upload__tip {
    margin-top: 0;
  }
  .avatar-uploader .el-upload {
    margin-bottom: 0;
    border: none;
  }
  .noImg {
    margin-left: 80px;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .imgavatar {
    width: 380px;
    height: 90px;
    display: block;
  }
  .avatar {
    height: 200px;
    width: 200px;
  }

  .hndetail-search {
    background-color: #fff;
    .svg-container {
      padding: 0 5px 0 10px;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .search-input {
      width: 78%;
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .el-button.is-round {
      float: right;
      padding: 10px 30px;
    }
  }
  .course-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .search-input {
      width: 50%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .course-search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .course-search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }
    &.merge {
      height: 50px;
      line-height: 50px;
    }
    &.separate {
      .course-search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }
      .course-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }
  .btn-container {
    display: flex;
    margin-top: 10px;
    .btn-container-title {
      flex: 1;
      height: 46px;
      line-height: 46px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }

  .classify-tab {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;
    .el-tabs__nav-wrap::after {
      display: none;
    }
    .el-tabs__header {
      margin: 0;
    }
  }
}
</style>

